#pragma once

#include <gofcl_dma_chxctl.h>

typedef enum {
	DMA_DIR_PHRI_TO_MEM = 0,
	DMA_DIR_MEM_TO_PHRI = 1,
} dma_dir_e;

typedef enum {
	DMA_NAGA_FIX = 0,
	DMA_NAGA_INCREASE = 1,
} dma_naga_e;

typedef enum {
	DMA_WIDTH_8_BITS = 0,
	DMA_WIDTH_16_BITS = 1,
	DMA_WIDTH_32_BITS = 2,
} dma_width_e;

typedef struct {
	u32_s channel_en : 1;
	u32_s full_finish_inter_en : 1;
	u32_s half_finish_inter_en : 1;
	u32_s error_inter_en : 1;
	dma_dir_e direction : 1;
	u32_s circular_mode_en : 1;
	dma_naga_e phri_next_addr_algorithm : 1;
	dma_naga_e mem_next_addr_algorithm : 1;
	dma_width_e phri_data_width : 2;
	dma_width_e mem_data_width : 2;
	u32_s priority : 2;
	u32_s mem_to_mem_mode_en : 1;
	u32_s : 17;
} dma_chxctl_expl_s;

_Static_assert(sizeof(dma_chxctl_expl_s) == 4,
	       "Struct dma_chxctl_expl_s defined error!");

static inline void dma_setup_channel_ctl(dma_qe dma_q, u32_s channel,
					 dma_chxctl_expl_s channel_ctl) {
	union {
		dma_chxctl_expl_s e;
		dma_chxctl_s c;
	} ec = {
		.e = channel_ctl,
	};
	dma_wreg_chxctl_s(dma_q, channel, ec.c);
}
